/**
 * Created by dqw on 2015/12/30.
 */
//列表开始
var cashstatus = {1: '待处理', 2: '待审核', 3: '待出账', 4: '提现成功', 5: "提现失败", 6: "提现取消"};
var dtGridColumns = [
    {
        id: 'delFlag',
        type: 'int',
        hideQuery:true,
        'export':false,
        hideQueryType:'eq',
        hideQueryValue:1,
        hide:true
    },
    {
        id: 'userId',
        type: 'number',
        hideQuery:true,
        'export':false,
        hide:true
    },
    {
        id: 'id',
        title: '提现记录ID',
        type: 'number',
        columnClass: 'text-center width-100',
        fastSort: false
    },
    {
        id: 'u.userName',
        title: '用户名',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-center width-100',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'realName',
        title: '真实姓名',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-center width-100',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'u.mobilePhone',
        title: '用户手机',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-center width-90',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'bankName',
        title: '银行名称',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: false
    },
    {
        id: 'bankNo',
        title: '银行卡号',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: false,
        fastQueryType: 'lk'
    },
    {
        id: 'branch',
        title: '支行名称',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-center width-200',
        fastSort: false,
        fastQuery: false,
        fastQueryType: 'lk'
    },
    {
        id: 'amount',
        title: '提现金额',
        type: 'number',
        headerClass: 'text-center',
        columnClass: 'text-center',
        format:'#,###.00',
        fastSort: false,
        fastQuery: false,
        fastQueryType: 'lk'
    },
    {
        id: 'status',
        title: '提现状态',
        type: 'int',
        codeTable: cashstatus,
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: false,
        fastQueryType: 'eq',
        codeTable:{
            1:$lang.cashStatus.T1,
            2:$lang.cashStatus.T2,
            3:$lang.cashStatus.T3,
            4:$lang.cashStatus.T4,
            5:$lang.cashStatus.T5,
            6:$lang.cashStatus.T6

        },
    },
    {
        id: 'remark',
        title: '备注',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: false,
        fastQueryType: 'lk',
        hideType: 'md|sm|xs|lg'
    },
    // {
    //     id: 'batchNo',
    //     title: '批次号',
    //     type: 'string',
    //     headerClass: 'text-center',
    //     columnClass: 'text-center',
    //     fastSort: false,
    //     fastQuery: true,
    //     fastQueryType: 'lk',
    //     hideType: 'md|sm|xs|lg'
    // },
    // {
    //     id: 'orderNo',
    //     title: '订单号',
    //     type: 'string',
    //     headerClass: 'text-center',
    //     columnClass: 'text-center',
    //     fastSort: false,
    //     fastQuery: true,
    //     fastQueryType: 'lk',
    //     hideType: 'md|sm|xs|lg'
    // },
    {
        id: 'orderNo',
        title: '订单号',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-left',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'outOrderNo',
        title: '外部单号',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-left',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'lk',
        hideType: 'md|sm|xs|lg'
    },
    {
        id: 'outStatus',
        title: '第三方返回状态',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-left',
        fastSort: false,
        hideType: 'md|sm|xs|lg',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            if(record.outStatus== undefined){
                return "--";
            }else{
                return record.outStatus;
            }
        }
    },
    {
        id: 'outMsg',
        title: '第三方返回消息',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-left',
        fastSort: false,
        hideType: 'md|sm|xs|lg',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            if(record.outMsg== undefined){
                return "--";
            }else{
                return record.outMsg;
            }
        }
    },
    {
        id: 'createTime',
        title: '提现时间',
        type: 'date',
        format:'yyyy-MM-dd',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'range'
    },
    // {
    //     id: 'updateTime',
    //     title: '审核时间',
    //     type: 'date',
    //     format:'yyyy-MM-dd',
    //     headerClass: 'text-center',
    //     columnClass: 'text-center',
    //     fastSort: true,
    //     fastQuery: true,
    //     fastQueryType: 'range'
    // },
    {
        id: 'cashVerify',
        title: '提现审核',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var pwdHtml = "<a data-target='#verifyModal' class='btn btn-sm btn-primary m-r-10' data-toggle='modal' data-no='" + dataNo + "'><i class='fa fa-edit'></i>&nbsp;审核&nbsp;</a>";
            var html = "";
            // 判断是否有编辑权限
            if ($("#verifyPermi") && $("#verifyPermi").val() == 1) {
                if (record.status == 2){
                    html += pwdHtml;
                }
            }
            return html;
        }
    },

];

var dtGridOption = {
    lang: 'zh-cn',
    ajaxLoad: true,
    loadURL: ncGlobal.adminRoot + 'cash/list.json',
    exportURL:ncGlobal.adminRoot + 'cash/export.json',
    exportFileName: '提现记录列表',
    columns: dtGridColumns,
    gridContainer: 'dtGridContainer',
    toolbarContainer: 'dtGridToolBarContainer',
    pageSize: 10,
    pageSizeLimit: [10, 20, 50],
    ncColumnsType: {BigDecimal:["amount"],int: ["status","userId"],Timestamp:["createTime"]},
    tools:'refresh|faseQuery|export[excel]',
};

var grid = $.fn.DtGrid.init(dtGridOption);
grid.fastQueryParameters = new Object();
grid.fastQueryParameters['eq_delFlag'] = 1;


//排序
grid.sortParameter.columnId = ['asc_id'];
// grid.sortParameter.sortType = 1;
//列表结束

//操作处理开始
var OperateHandle = function () {

    function _bindEvent() {

        //新增对话框初始化
        $("#addModal").on("show.bs.modal", function (event) {
            //清除错误信息
            $(".alert-danger").remove();
            $("#addForm").psly().reset();
            $.each($("#addForm input"),function (i, v) {
                $(v).val('');
            })
        });

        //编辑对话框初始化
        $("#editModal").on("show.bs.modal", function (event) {
            //清除错误信息
            $(".alert-danger").remove();
            $("#editForm").psly().reset();
            //获取接受事件的元素
            var button = $(event.relatedTarget);
            //获取data 参数
            var datano = button.data('no');
            var modal = $(this);
            //获取列表框中的原始数据
            var gridData = grid.sortOriginalDatas[datano];
            investAccount = gridData.investAccount;

            $("#investId").val(gridData.id);
            $("#adminName").val(gridData.name);
            modal.find("[name='password']").val("");
            modal.find("[name='password2']").val("");
            modal.find("[name='roleId']").val(gridData.roleId);
        });

        //开始审核
        $("#verifyModal").on("show.bs.modal", function (event) {
            //清除错误信息
            $(".alert-danger").remove();
            $("#verifyForm").psly().reset();
            //获取接受事件的元素
            var button = $(event.relatedTarget);
            //获取data 参数
            var datano = button.data('no');
            var gridData = grid.sortOriginalDatas[datano];
            var model = $(this);
            model.find('input[name="id"]').val(gridData.id);
            model.find('input[name="realName"]').val(gridData.realName);
            model.find('input[name="amount"]').val(gridData.amount);
            model.find('input[name="bankName"]').val(gridData.bankName);
            model.find('input[name="bankNo"]').val(gridData.bankNo);
            model.find('textarea[name="remark"]').val('');
            $(".status").bootstrapSwitch('state', true);
        });

        //模糊搜索
        $('#customSearch').click(function () {
            grid.fastQueryParameters = new Object();
            grid.fastQueryParameters['eq_delFlag'] = 1;
            grid.fastQueryParameters['lk_u.user_name_or_like_u.mobile_phone_or_like_real_name'] = $('#keyword').val();
            grid.pager.startRecord = 0;
            grid.pager.nowPage = 1;
            grid.pager.recordCount = -1;
            grid.pager.pageCount = -1;
            grid.refresh(true);
        });
    }

    //外部可调用
    return {
        bindEvent: _bindEvent
    }
}();
//操作处理结束

$(function () {
    //加载列表
    grid.load();
    //页面绑定事件
    OperateHandle.bindEvent();
});